package com.ys.service.storage.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ys.dto.AddDto;
import com.ys.entity.base.TbCountry;
import com.ys.entity.purchase.TcgDistribution;
import com.ys.entity.storage.*;
import com.ys.entity.storage.TccLogisticsMethod;
import com.ys.entity.sys.TsUserChange;
import com.ys.entity.sys.YsCol;
import com.ys.enume.storage.TccFbaLogisticsMethodEnum;
import com.ys.mapper.business.DiySqlMapper;
import com.ys.mapper.storage.*;
import com.ys.service.storage.TccLogisticsMethodService;
import com.ys.util.CheckUtil;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: fxz
 * @CreateTime: 2024-12-05
 * @Description: 物流方式
 * @Version: 1.5
 */
@Service("tccLogisticsMethodService")
public class TccLogisticsMethodServiceImpl implements TccLogisticsMethodService {
    private static final Logger logger = LoggerFactory.getLogger(TccLogisticsMethodServiceImpl.class);
    @Autowired
    private StorageMapper storageMapper;

    @Autowired
    private  TccLogisticsMethodMapper tccLogisticsMethodMapper;

    @Autowired
    private TccLogisticsMethodItemMapper tccLogisticsMethodItemMapper;

    @Autowired
    private TccLogisticsMethodItemSonMapper tccLogisticsMethodItemSonMapper;

    @Autowired
    private TccAdditionalBillingMapper tccAdditionalBillingMapper;

    @Autowired
    private TccAdditionalBillingTwoMapper tccAdditionalBillingTwoMapper;

    @Autowired
    private TccLogisticsCompanyApplyMapper tccLogisticsCompanyApplyMapper;

    @Autowired
    private CheckUtil checkUtil;

    /**
     * 新增
     */
    @Override
    @Transactional(timeout = 120, propagation = Propagation.REQUIRES_NEW)
    public R add(Map<String, Object> params, Long menuId) throws Exception {
        logger.info("新增传参:" + params);
        //参数验证
        String errorBack = checkParams(params, menuId);
        if (errorBack != null && !"".equals(errorBack)) {
            return R.error(errorBack);
        }
        TccLogisticsMethod tccLogisticsMethod = JSON.parseObject(JSON.toJSONString(params), TccLogisticsMethod.class);
        TccWarehouse tccWarehouse = JSON.parseObject(JSON.toJSONString(params), TccWarehouse.class);

        Map<String, Object> tccLogisticsMethod1 = new TccLogisticsMethod()
                .addLeftJoin("TCC_Warehouse B ON B.Cck=A.Cck")
                .addLeftJoin("TB_Country C ON C.Code=A.DestinationCountryCode")
                .addField("B.Vck vck,C.Name destinationCountryName")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(params.get("subData").toString());//获取列表信息
        String itemList = jsonObject.getString("itemList");//
        String itemList2 = jsonObject.getString("itemList2");//
        String itemList3 = jsonObject.getString("itemList3");//
        String itemList4 = jsonObject.getString("itemList4");//
        String itemList5 = jsonObject.getString("itemList5");//
        String itemList6 = jsonObject.getString("itemList6");//


            if (!params.get("singlePassCrane").toString().matches("\\d+(\\.\\d{0,2})?")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return R.error("单票起重的值不能大于两位小数点！");
            } else if (tccLogisticsMethod.getEstimatedDayFrom() < 0) {
                return R.error("预估时效F（天）必须大于0");
            } else if (tccLogisticsMethod.getEstimatedDayTo() < 0) {
                return R.error("预估时效T（天）必须大于0");
            } else if (!params.get("weightCalBySingle").toString().matches("\\d+(\\.\\d{0,2})?")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return R.error("单箱起重的值不能大于两位小数点！");
            } else if (!params.get("additionalStandardAmount").toString().matches("\\d+(\\.\\d{0,2})?")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return R.error("品名附加计费标准的值不能大于两位小数点！");
            } else if (!params.get("additionalStandardAmount").toString().matches("\\d+(\\.\\d{0,2})?")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return R.error("品名附加计费标准的值不能大于两位小数点！");
            }  else if (tccLogisticsMethod.getEstimatedDayFrom() > tccLogisticsMethod.getEstimatedDayTo()) {
                return R.error("预估时效F不能比预估时效T大");
            }  else if (tccLogisticsMethod.getFreeProNameNum() > tccLogisticsMethod.getMaxProNameNum()) {
                return R.error("单票品名免费数量不能比单票品名上限数量大");
            } else if (tccLogisticsMethod.getSingleBoxReqAmountMin().compareTo(tccLogisticsMethod.getSingleBoxReqAmountMax()) >0 ) {
                return R.error("单箱采购最低价不能比单箱采购最高价高");
            } else if (tccLogisticsMethod.getWeightCalBySingle().compareTo(tccLogisticsMethod.getSinglePassCrane()) >0 ) {
                return R.error("单箱起重不能比单票起重大");
            }
        BigDecimal singleBoxReqAmountMin = new BigDecimal(params.get("singleBoxReqAmountMin").toString());
            if (singleBoxReqAmountMin == null) {
                return R.error("单箱采购最低价不能为空");
            } else if (singleBoxReqAmountMin.compareTo(BigDecimal.ZERO) < 0) {
                return R.error("单箱采购最低价必须大于0");
            }
            BigDecimal singleBoxReqAmountMax = new BigDecimal(params.get("singleBoxReqAmountMax").toString());
            if (singleBoxReqAmountMax == null) {
                return R.error("单箱采购最高价不能为空");
            } else if (singleBoxReqAmountMax.compareTo(BigDecimal.ZERO) < 0) {
                return R.error("单箱采购最高价必须大于0");
            }
            BigDecimal clearanceOpeAmount = new BigDecimal(params.get("clearanceOpeAmount").toString());
            if (clearanceOpeAmount == null) {
                return R.error("清关服务费不能为空");
            } else if (clearanceOpeAmount.compareTo(BigDecimal.ZERO) < 0) {
                return R.error("清关服务费必须大于0");
            }
            BigDecimal freeProNameNum = new BigDecimal(params.get("freeProNameNum").toString());
            if (freeProNameNum == null) {
                return R.error("单票品名免费数量不能为空");
            } else if (freeProNameNum.compareTo(BigDecimal.ZERO) < 0) {
                return R.error("单票品名免费数量必须大于0");
            }
            BigDecimal maxProNameNum =new BigDecimal(params.get("maxProNameNum").toString());
            if (maxProNameNum == null) {
                return R.error("单票品名上限数量不能为空");
            } else if (maxProNameNum.compareTo(BigDecimal.ZERO) < 0) {
                return R.error("单票品名上限数量必须大于0");
            }
            //判断是否唯一
            String destinationCountryCode=params.get("destinationCountryCode").toString();
            String cck=params.get("cck").toString();
            Integer estimatedDayFrom=tccLogisticsMethod.getEstimatedDayFrom();
            Integer estimatedDayTo=tccLogisticsMethod.getEstimatedDayTo();
            Long transportationId=tccLogisticsMethod.getTransportationId();
            String remark=params.get("remark").toString();
            Integer nameLogsticsClearance1=tccLogisticsMethod.getNameLogsticsClearance();
            if(remark == null || remark.equals("")){
                remark=null;
            }
            if (new TccLogisticsMethod().setDestinationCountryCode(destinationCountryCode).setCck(cck).setEstimatedDayFrom(estimatedDayFrom).setNameLogsticsClearance(nameLogsticsClearance1).setEstimatedDayTo(estimatedDayTo).setTransportationId(transportationId).setRemark(remark).count()>0){
                return R.error("该物流服务名称已使用,请核实后再操作!");
            }
            String logsticsWay = "";
            String vck = "";
            if (tccLogisticsMethod.getCck().equals("CK0001")){
                vck = "福州仓";
            }

            String transportationName = "";
            if (tccLogisticsMethod.getTransportationId()==0){
                transportationName = "快递";
            }else if (tccLogisticsMethod.getTransportationId()==1){
                transportationName = "空运";
            }else if (tccLogisticsMethod.getTransportationId()==2){
                transportationName = "卡航";
            }else if (tccLogisticsMethod.getTransportationId()==3){
                transportationName = "铁路";
            }else if (tccLogisticsMethod.getTransportationId()==4){
                transportationName = "海运";
            }

            String nameLogsticsClearance = "";
            if (tccLogisticsMethod.getNameLogsticsClearance().equals(TccFbaLogisticsMethodEnum.NameLogsticsClearance.SELFTAX.value)){
                nameLogsticsClearance = "自税";
            }else if (tccLogisticsMethod.getTransportationId().equals(TccFbaLogisticsMethodEnum.NameLogsticsClearance.FARMINGTAXES.value)){
                nameLogsticsClearance = "包税";
                tccLogisticsMethod.setClearanceOpeAmount(BigDecimal.ZERO);
            }else if (tccLogisticsMethod.getTransportationId().equals(TccFbaLogisticsMethodEnum.NameLogsticsClearance.FARMINGTAXESDF.value)){
                nameLogsticsClearance = "包税单发";
                tccLogisticsMethod.setClearanceOpeAmount(BigDecimal.ZERO);
            }

        logsticsWay = params.get("destinationCountryName").toString()+"-"+transportationName+nameLogsticsClearance+"-"+params.get("remark")+"("+ tccLogisticsMethod.getEstimatedDayFrom()+"~"+ tccLogisticsMethod.getEstimatedDayTo()+"天"+")";

        //新增
        tccLogisticsMethodMapper.insert(tccLogisticsMethod);

        //保存，物流服务维护管理子表
        if(itemList!=null && !"".equals(itemList)){
            JSONArray arrayInfo = JSON.parseArray(itemList);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject item=arrayInfo.getJSONObject(i);
                TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                BigDecimal heavyEn=tccLogisticsMethodItem.getHeavyEn();
                BigDecimal heavySn=tccLogisticsMethodItem.getHeavySn();
                BigDecimal price=tccLogisticsMethodItem.getPrice();
                if(heavyEn==null||"".equals(heavyEn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("最终重量为空");
                }
                if(heavySn==null||"".equals(heavySn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("起始重量为空");
                }
                if(price==null||"".equals(price)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("计重费为空");
                }
                if (!checkUtil.isDecimal(item.get("heavySn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("起始重量的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("heavyEn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("最终重量的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("price").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("计重费（￥/kg）的值不能大于两位小数点！");
                }
                if ( heavySn.compareTo(heavyEn)>0 ) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("初始重量不能比最终重量大");
                }
                if(i!=0){
                    JSONObject itembefore=arrayInfo.getJSONObject(i-1);
                    BigDecimal heavySn1 = new BigDecimal(item.get("heavySn").toString());
                    BigDecimal heavyEn1 = new BigDecimal(itembefore.get("heavyEn").toString());
                    if ( heavySn1.compareTo(heavyEn1)<=0 ) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("新的一条初始重量不能比上一条的最终重量小");
                    }

                }
            }
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                    tccLogisticsMethodItem.setStatus(1);
                    tccLogisticsMethodItem.setLogisticsMethodType(0);
                    tccLogisticsMethodItem.setMethodId(tccLogisticsMethod.getId());
                    tccLogisticsMethodItemMapper.insert(tccLogisticsMethodItem);
                }
            }
        }


        //保存，物流服务维护表
        if(itemList2!=null && !"".equals(itemList2)){
            JSONArray arrayInfo = JSON.parseArray(itemList2);
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    JSONObject item=arrayInfo.getJSONObject(i);
                    TccLogisticsMethodItemSon tccLogisticsMethodItemSon = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItemSon.class);
                    BigDecimal additionalMaterialBilling=tccLogisticsMethodItemSon.getAdditionalMaterialBilling();
                    if(additionalMaterialBilling==null||"".equals(additionalMaterialBilling)){
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("材质附加计费为空");
                    }
                    if (!checkUtil.isDecimal(item.get("additionalMaterialBilling").toString(),"2")){
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("材质附加计费的值不能大于两位小数点！");
                    }

                }
                if(arrayInfo!=null && arrayInfo.size()>0){
                    logger.info("物流服务维护管理子表信息："+arrayInfo);
                    for(int i=0;i<arrayInfo.size();i++){
                        TccLogisticsMethodItemSon tccLogisticsMethodItemSon = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItemSon.class);
                        tccLogisticsMethodItemSon.setStatus(1);
                        tccLogisticsMethodItemSon.setMethodId(tccLogisticsMethod.getId());
                        tccLogisticsMethodItemSonMapper.insert(tccLogisticsMethodItemSon);
                    }
                }
            }
        }
        //保存，物流服务维护管理子表
        if(itemList3!=null && !"".equals(itemList3)){
            JSONArray arrayInfo = JSON.parseArray(itemList3);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject item=arrayInfo.getJSONObject(i);
                TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                BigDecimal heavyEn=tccLogisticsMethodItem.getHeavyEn();
                BigDecimal heavySn=tccLogisticsMethodItem.getHeavySn();
                BigDecimal price=tccLogisticsMethodItem.getPrice();
                if(heavyEn==null||"".equals(heavyEn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重启始为空");
                }
                if(heavySn==null||"".equals(heavySn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重最终为空");
                }
                if(price==null||"".equals(price)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费为空");
                }
//                if (tccLogisticsMethod.getNameLogsticsClearance().equals(0)){
//                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//                    return R.error("自税不能新增抛重附加计费标准");
//                }
                if (!checkUtil.isDecimal(item.get("heavyEn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重启始（kg）的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("heavySn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重最终（kg）的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("price").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费（￥/kg）的值不能大于两位小数点！");
                }
                if ( heavySn.compareTo(heavyEn)>0 ) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重启始不能比抛重最终大");
                }
                if(i!=0){
                    JSONObject itembefore=arrayInfo.getJSONObject(i-1);
                    BigDecimal heavySn1 = new BigDecimal(item.get("heavySn").toString());
                    BigDecimal heavyEn1 = new BigDecimal(itembefore.get("heavyEn").toString());
                    if ( heavySn1.compareTo(heavyEn1)<=0 ) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("新的一条抛重启始不能比上一条的抛重最终小");
                    }

                }
            }
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                    tccLogisticsMethodItem.setStatus(1);
                    tccLogisticsMethodItem.setLogisticsMethodType(1);
                    tccLogisticsMethodItem.setMethodId(tccLogisticsMethod.getId());
                    tccLogisticsMethodItemMapper.insert(tccLogisticsMethodItem);

                }
            }
        }

        Map<String,String> map = new HashMap<>();
        //保存，物流服务维护管理子表
        if(itemList4!=null && !"".equals(itemList4)){
            JSONArray arrayInfo = JSON.parseArray(itemList4);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject jsonObject1 = JSON.parseObject(arrayInfo.get(i).toString());

                Boolean firstPostalCodeState = false;
                if(jsonObject1.get("firstPostalCode")==null||"".equals(jsonObject1.get("firstPostalCode"))){
                    firstPostalCodeState = true;
                }

                Boolean warehouseCode = false;
                if(jsonObject1.get("warehouseCode")==null||"".equals(jsonObject1.get("warehouseCode"))){
                    warehouseCode = true;
                }

                if (firstPostalCodeState == true && warehouseCode == true){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("邮编首数字和仓库代码不能同时为空!");
                }

                if(jsonObject1.get("additionalBilling")==null||"".equals(jsonObject1.get("additionalBilling"))){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费为空");
                }
                if (!checkUtil.isDecimal(jsonObject1.get("additionalBilling").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费（￥/kg）的值不能大于两位小数点！");
                }

                TccAdditionalBilling tccAdditionalBilling = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccAdditionalBilling.class);
                String warehouseArea=tccAdditionalBilling.getWarehouseArea();
                String firstPostalCode=tccAdditionalBilling.getFirstPostalCode();

                String key = warehouseArea + firstPostalCode + tccAdditionalBilling + warehouseCode;
                if (map.get(key) == null){
                    map.put(key,key);
                }else {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("不能新增相同数据");
                }
            }

            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccAdditionalBilling tccAdditionalBilling = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccAdditionalBilling.class);
                    tccAdditionalBilling.setStatus(1);
                    if(tccAdditionalBilling.getFirstPostalCode()==null || "".equals(tccAdditionalBilling.getFirstPostalCode())){
                        tccAdditionalBilling.setFirstPostalCode(null);
                    }
                    if(tccAdditionalBilling.getWarehouseCode()==null || "".equals(tccAdditionalBilling.getWarehouseCode())){
                        tccAdditionalBilling.setWarehouseCode(null);
                    }
                    if(tccAdditionalBilling.getWarehouseArea()==null || "".equals(tccAdditionalBilling.getWarehouseArea())){
                        tccAdditionalBilling.setWarehouseArea(null);
                    }
                    tccAdditionalBilling.setMethodId(tccLogisticsMethod.getId());
                    tccAdditionalBillingMapper.insert(tccAdditionalBilling);
                }
            }
        }

        //保存，物流服务维护表
        if(itemList5!=null && !"".equals(itemList5)){
            JSONArray arrayInfo = JSON.parseArray(itemList5);
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    JSONObject item=arrayInfo.getJSONObject(i);

                }
                if(arrayInfo!=null && arrayInfo.size()>0){
                    logger.info("物流服务维护管理子表信息："+arrayInfo);
                    for(int i=0;i<arrayInfo.size();i++){
                        TccLogisticsCompanyApply tccLogisticsCompanyApply = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsCompanyApply.class);
                        tccLogisticsCompanyApply.setStatus(1);
                        tccLogisticsCompanyApply.setMethodId(tccLogisticsMethod.getId());
                        tccLogisticsCompanyApplyMapper.insert(tccLogisticsCompanyApply);
                    }
                }
            }
        }
        //保存，物流服务维护管理子表
        if(itemList6!=null && !"".equals(itemList6)){
            JSONArray arrayInfo = JSON.parseArray(itemList6);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject jsonObject1 = JSON.parseObject(arrayInfo.get(i).toString());

                String warehouseCode;
                if (jsonObject1.get("warehouseCode") == null){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("仓库代码不能为空!");
                }
                warehouseCode=jsonObject1.get("warehouseCode").toString();
                String key = warehouseCode;
                if (map.get(warehouseCode) == null){
                    map.put(warehouseCode,key);
                }else {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("不能新增相同数据");
                }
            }
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccAdditionalBillingTwo tccAdditionalBillingTwo = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccAdditionalBillingTwo.class);
                    tccAdditionalBillingTwo.setStatus(1);
                    tccAdditionalBillingTwo.setMethodId(tccLogisticsMethod.getId());
                    tccAdditionalBillingTwoMapper.insert(tccAdditionalBillingTwo);

                }
            }
        }


        return R.ok(AddDto.gotoEdit("/web/storage/tccLogisticsMethod/toEdit?id=" + tccLogisticsMethod.getId()));
        //return R.ok();
    }

    /**
     * 保存
     */
    @Override
    @Transactional(timeout = 120, propagation = Propagation.REQUIRES_NEW)
    public R save(Map<String, Object> params, Long menuId) throws Exception {
        logger.info("物流服务维护管理保存传参："+params);

        //参数验证
        String errorMsg = checkParams(params,menuId);
        if(errorMsg!=null && !"".equals(errorMsg)){
            return R.error(errorMsg);
        }
        TccLogisticsMethod tccLogisticsMethod = JSON.parseObject(JSON.toJSONString(params), TccLogisticsMethod.class);
        TccWarehouse tccWarehouse = JSON.parseObject(JSON.toJSONString(params), TccWarehouse.class);

        Map<String, Object> tccLogisticsMethod1 = new TccLogisticsMethod()
                .addLeftJoin("TCC_Warehouse B ON B.Cck=A.Cck")
                .addLeftJoin("TB_Country C ON C.Code=A.DestinationCountryCode")
                .addField("B.Vck vck,C.Name destinationCountryName")
                .queryFirstMap();
        //判断是否唯一
        String destinationCountryCode=params.get("destinationCountryCode").toString();
        String cck=params.get("cck").toString();
        Integer estimatedDayFrom=tccLogisticsMethod.getEstimatedDayFrom();
        Integer estimatedDayTo=tccLogisticsMethod.getEstimatedDayTo();
        Long transportationId=tccLogisticsMethod.getTransportationId();
        String remark=params.get("remark").toString();
        Integer nameLogsticsClearance1=tccLogisticsMethod.getNameLogsticsClearance();
        String sql = "";
        if (tccLogisticsMethod.getId() != null){
            sql = "A.id != " + tccLogisticsMethod.getId() ;
        }
        if(remark == null || remark.equals("")){
            sql = sql + " AND A.remark IS NULL";
        }
        if (new TccLogisticsMethod().setDestinationCountryCode(destinationCountryCode).setCck(cck).setEstimatedDayFrom(estimatedDayFrom).setNameLogsticsClearance(nameLogsticsClearance1).setEstimatedDayTo(estimatedDayTo).setTransportationId(transportationId).setRemark(remark).where(sql).count()>0){
            return R.error("该物流服务名称已使用,请核实后再操作!");
        }
        String logsticsWay = "";

        String transportationName = "";
        if (tccLogisticsMethod.getTransportationId() == 0){
            transportationName = "快递";
        }else if (tccLogisticsMethod.getTransportationId() == 1){
            transportationName = "空运";
        }else if (tccLogisticsMethod.getTransportationId() == 2){
            transportationName = "卡航";
        }else if (tccLogisticsMethod.getTransportationId() == 3){
            transportationName = "铁路";
        }else if (tccLogisticsMethod.getTransportationId() == 4){
            transportationName = "海运";
        }

        String nameLogsticsClearance = "";
        if (tccLogisticsMethod.getNameLogsticsClearance().equals(TccFbaLogisticsMethodEnum.NameLogsticsClearance.SELFTAX.value)){
            nameLogsticsClearance = "自税";
        }else if (tccLogisticsMethod.getTransportationId().equals(TccFbaLogisticsMethodEnum.NameLogsticsClearance.FARMINGTAXES.value)){
            nameLogsticsClearance = "包税";
            tccLogisticsMethod.setClearanceOpeAmount(BigDecimal.ZERO);
        }else if (tccLogisticsMethod.getTransportationId().equals(TccFbaLogisticsMethodEnum.NameLogsticsClearance.FARMINGTAXESDF.value)){
            nameLogsticsClearance = "包税单发";
            tccLogisticsMethod.setClearanceOpeAmount(BigDecimal.ZERO);
        }

        logsticsWay = params.get("destinationCountryName").toString()+"-"+transportationName+nameLogsticsClearance+"-"+params.get("remark")+"("+ tccLogisticsMethod.getEstimatedDayFrom()+"~"+ tccLogisticsMethod.getEstimatedDayTo()+"天"+")";

        tccLogisticsMethod.setLogsticsWay(logsticsWay);

        JSONObject jsonObject = JSONObject.parseObject(params.get("subData").toString());//获取列表信息
        String itemList = jsonObject.getString("itemList");//
        String itemList2 = jsonObject.getString("itemList2");//
        String itemList3 = jsonObject.getString("itemList3");//
        String itemList4 = jsonObject.getString("itemList4");//
        String itemList5 = jsonObject.getString("itemList5");//
        String itemList6 = jsonObject.getString("itemList6");//
        if (!params.get("singlePassCrane").toString().matches("\\d+(\\.\\d{0,2})?")) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单票起重的值不能大于两位小数点！");
        } else if (tccLogisticsMethod.getEstimatedDayFrom() < 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("预估时效F（天）必须大于0");
        } else if (tccLogisticsMethod.getEstimatedDayTo() < 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("预估时效T（天）必须大于0");
        } else if (!params.get("weightCalBySingle").toString().matches("\\d+(\\.\\d{0,2})?")) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单箱起重的值不能大于两位小数点！");
        } else if (!params.get("additionalStandardAmount").toString().matches("\\d+(\\.\\d{0,2})?")) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("品名附加计费标准的值不能大于两位小数点！");
        } else if (!params.get("additionalStandardAmount").toString().matches("\\d+(\\.\\d{0,2})?")) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("品名附加计费标准的值不能大于两位小数点！");
        } else if (tccLogisticsMethod.getEstimatedDayFrom() > tccLogisticsMethod.getEstimatedDayTo()) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("预估时效F不能比预估时效T大");
        } else if (tccLogisticsMethod.getFreeProNameNum() > tccLogisticsMethod.getMaxProNameNum()) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单票品名免费数量不能比单票品名上限数量大");
        } else if (tccLogisticsMethod.getSingleBoxReqAmountMin().compareTo(tccLogisticsMethod.getSingleBoxReqAmountMax()) >0 ) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单箱采购最低价不能比单箱采购最高价高");
        } else if (tccLogisticsMethod.getWeightCalBySingle().compareTo(tccLogisticsMethod.getSinglePassCrane()) >0 ) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单箱起重不能比单票起重大");
        }
        BigDecimal singleBoxReqAmountMin = new BigDecimal(params.get("singleBoxReqAmountMin").toString());
        if (singleBoxReqAmountMin == null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单箱采购最低价不能为空");
        } else if (singleBoxReqAmountMin.compareTo(BigDecimal.ZERO) < 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单箱采购最低价必须大于0");
        }
        BigDecimal singleBoxReqAmountMax = new BigDecimal(params.get("singleBoxReqAmountMax").toString());
        if (singleBoxReqAmountMax == null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单箱采购最高价不能为空");
        } else if (singleBoxReqAmountMax.compareTo(BigDecimal.ZERO) < 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单箱采购最高价必须大于0");
        }
        BigDecimal clearanceOpeAmount = new BigDecimal(params.get("clearanceOpeAmount").toString());
        if (clearanceOpeAmount == null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("清关服务费不能为空");
        } else if (clearanceOpeAmount.compareTo(BigDecimal.ZERO) < 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("清关服务费必须大于0");
        }
        BigDecimal freeProNameNum = new BigDecimal(params.get("freeProNameNum").toString());
        if (freeProNameNum == null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单票品名免费数量不能为空");
        } else if (freeProNameNum.compareTo(BigDecimal.ZERO) < 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单票品名免费数量必须大于0");
        }
        BigDecimal maxProNameNum =new BigDecimal(params.get("maxProNameNum").toString());
        if (maxProNameNum == null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单票品名上限数量不能为空");
        } else if (maxProNameNum.compareTo(BigDecimal.ZERO) < 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.error("单票品名上限数量必须大于0");
        }
        //主表信息保存
        tccLogisticsMethodMapper.update(tccLogisticsMethod);



        //保存，物流服务维护管理子表
        storageMapper.deleteBatchTccLogisticsMethodItemById(tccLogisticsMethod.getId());
        if(itemList!=null && !"".equals(itemList)){
            JSONArray arrayInfo = JSON.parseArray(itemList);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject item=arrayInfo.getJSONObject(i);
                TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                BigDecimal heavyEn=tccLogisticsMethodItem.getHeavyEn();
                BigDecimal heavySn=tccLogisticsMethodItem.getHeavySn();
                BigDecimal price=tccLogisticsMethodItem.getPrice();
                if(heavyEn==null||"".equals(heavyEn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("最终重量为空");
                }
                if(heavySn==null||"".equals(heavySn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("起始重量为空");
                }
                if(price==null||"".equals(price)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("计重费为空");
                }
                if (!checkUtil.isDecimal(item.get("heavySn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("起始重量的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("heavyEn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("最终重量的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("price").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("计重费（￥/kg）的值不能大于两位小数点！");
                }
                if ( heavySn.compareTo(heavyEn)>0 ) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("初始重量不能比最终重量大");
                }
                if(i!=0){
                    JSONObject itembefore=arrayInfo.getJSONObject(i-1);
                    BigDecimal heavySn1 = new BigDecimal(item.get("heavySn").toString());
                    BigDecimal heavyEn1 = new BigDecimal(itembefore.get("heavyEn").toString());
                    if ( heavySn1.compareTo(heavyEn1)<=0 ) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("新的一条初始重量不能比上一条的最终重量小");
                    }

                }
            }
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                    tccLogisticsMethodItem.setStatus(1);
                    tccLogisticsMethodItem.setLogisticsMethodType(0);
                    tccLogisticsMethodItem.setMethodId(tccLogisticsMethod.getId());

                    tccLogisticsMethodItemMapper.insert(tccLogisticsMethodItem);

                }
            }
        }


        //删除子件表信息
        storageMapper.deleteBatchTccLogisticsMethodItemSonById(tccLogisticsMethod.getId());
        //保存，物流服务维护表
        if(itemList2!=null && !"".equals(itemList2)){
            JSONArray arrayInfo = JSON.parseArray(itemList2);
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    JSONObject item=arrayInfo.getJSONObject(i);
                    TccLogisticsMethodItemSon tccLogisticsMethodItemSon = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItemSon.class);
                    BigDecimal additionalMaterialBilling=tccLogisticsMethodItemSon.getAdditionalMaterialBilling();
                    if(additionalMaterialBilling==null||"".equals(additionalMaterialBilling)){
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("材质附加计费为空");
                    }
                    if (!checkUtil.isDecimal(item.get("additionalMaterialBilling").toString(),"2")){
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("材质附加计费的值不能大于两位小数点！");
                    }

                }
                if(arrayInfo!=null && arrayInfo.size()>0){
                    logger.info("物流服务维护管理子表信息："+arrayInfo);
                    for(int i=0;i<arrayInfo.size();i++){
                        TccLogisticsMethodItemSon tccLogisticsMethodItemSon = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItemSon.class);
                        tccLogisticsMethodItemSon.setStatus(1);
                        tccLogisticsMethodItemSon.setMethodId(tccLogisticsMethod.getId());
                        tccLogisticsMethodItemSonMapper.insert(tccLogisticsMethodItemSon);

                    }
                }
            }
        }
        //保存，物流服务维护管理子表
        storageMapper.deleteBatchTccLogisticsMethodItemTwoById(tccLogisticsMethod.getId());
        if(itemList3!=null && !"".equals(itemList3)){
            JSONArray arrayInfo = JSON.parseArray(itemList3);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject item=arrayInfo.getJSONObject(i);
                TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                BigDecimal heavyEn=tccLogisticsMethodItem.getHeavyEn();
                BigDecimal heavySn=tccLogisticsMethodItem.getHeavySn();
                BigDecimal price=tccLogisticsMethodItem.getPrice();
                if(heavyEn==null||"".equals(heavyEn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重启始为空");
                }
                if(heavySn==null||"".equals(heavySn)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重最终为空");
                }
                if(price==null||"".equals(price)){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费为空");
                }
                if (!checkUtil.isDecimal(item.get("heavyEn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重启始（kg）的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("heavySn").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重最终（kg）的值不能大于两位小数点！");
                }
                if (!checkUtil.isDecimal(item.get("price").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费（￥/kg）的值不能大于两位小数点！");
                }
                if ( heavySn.compareTo(heavyEn)>0 ) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("抛重启始不能比抛重最终大");
                }
                if(i!=0){
                    JSONObject itembefore=arrayInfo.getJSONObject(i-1);
                    BigDecimal heavySn1 = new BigDecimal(item.get("heavySn").toString());
                    BigDecimal heavyEn1 = new BigDecimal(itembefore.get("heavyEn").toString());
                    if ( heavySn1.compareTo(heavyEn1)<=0 ) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return R.error("新的一条抛重启始不能比上一条的抛重最终小");
                    }

                }
            }
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccLogisticsMethodItem tccLogisticsMethodItem = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsMethodItem.class);
                    tccLogisticsMethodItem.setStatus(1);
                    tccLogisticsMethodItem.setLogisticsMethodType(1);
                    tccLogisticsMethodItem.setMethodId(tccLogisticsMethod.getId());
                    tccLogisticsMethodItemMapper.insert(tccLogisticsMethodItem);

                }
            }
        }

        //保存，物流服务维护管理子表
        storageMapper.deleteBatchTccAdditionalBillingById(tccLogisticsMethod.getId());
        Map<String,String> map = new HashMap<>();
        //保存，物流服务维护管理子表
        if(itemList4!=null && !"".equals(itemList4)){
            JSONArray arrayInfo = JSON.parseArray(itemList4);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject jsonObject1 = JSON.parseObject(arrayInfo.get(i).toString());

                Boolean firstPostalCodeState = false;
                if(jsonObject1.get("firstPostalCode")==null||"".equals(jsonObject1.get("firstPostalCode"))){
                    firstPostalCodeState = true;
                }

                Boolean warehouseCode = false;
                if(jsonObject1.get("warehouseCode")==null||"".equals(jsonObject1.get("warehouseCode"))){
                    warehouseCode = true;
                }

                if (firstPostalCodeState == true && warehouseCode == true){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("邮编首数字和仓库代码不能同时为空!");
                }

                if(jsonObject1.get("additionalBilling")==null||"".equals(jsonObject1.get("additionalBilling"))){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费为空");
                }
                if (!checkUtil.isDecimal(jsonObject1.get("additionalBilling").toString(),"2")){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("附加计费（￥/kg）的值不能大于两位小数点！");
                }

                TccAdditionalBilling tccAdditionalBilling = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccAdditionalBilling.class);
                String warehouseArea=tccAdditionalBilling.getWarehouseArea();
                String firstPostalCode=tccAdditionalBilling.getFirstPostalCode();

                String key = warehouseArea + firstPostalCode + tccAdditionalBilling + warehouseCode;

                if (map.get(key) == null){
                    map.put(key,key);
                }else {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("不能新增相同数据");
                }
            }

            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccAdditionalBilling tccAdditionalBilling = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccAdditionalBilling.class);
                    tccAdditionalBilling.setStatus(1);
                    if(tccAdditionalBilling.getFirstPostalCode()==null || "".equals(tccAdditionalBilling.getFirstPostalCode())){
                        tccAdditionalBilling.setFirstPostalCode(null);
                    }
                    if(tccAdditionalBilling.getWarehouseCode()==null || "".equals(tccAdditionalBilling.getWarehouseCode())){
                        tccAdditionalBilling.setWarehouseCode(null);
                    }
                    if(tccAdditionalBilling.getWarehouseArea()==null || "".equals(tccAdditionalBilling.getWarehouseArea())){
                        tccAdditionalBilling.setWarehouseArea(null);
                    }
                    tccAdditionalBilling.setMethodId(tccLogisticsMethod.getId());
                    tccAdditionalBillingMapper.insert(tccAdditionalBilling);
                }
            }
        }
        storageMapper.deleteBatchTccLogisticsCompanyApplyById(tccLogisticsMethod.getId());
        //保存，物流服务维护表
        if(itemList5!=null && !"".equals(itemList5)){
            JSONArray arrayInfo = JSON.parseArray(itemList5);
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    JSONObject item=arrayInfo.getJSONObject(i);

                }
                if(arrayInfo!=null && arrayInfo.size()>0){
                    logger.info("物流服务维护管理子表信息："+arrayInfo);
                    for(int i=0;i<arrayInfo.size();i++){
                        TccLogisticsCompanyApply tccLogisticsCompanyApply = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccLogisticsCompanyApply.class);
                        tccLogisticsCompanyApply.setStatus(1);
                        tccLogisticsCompanyApply.setMethodId(tccLogisticsMethod.getId());
                        tccLogisticsCompanyApplyMapper.insert(tccLogisticsCompanyApply);

                    }
                }
            }
        }
        //保存，物流服务维护管理子表
        storageMapper.deleteBatchTccAdditionalBillingTwoById(tccLogisticsMethod.getId());
        //保存，物流服务维护管理子表
        if(itemList6!=null && !"".equals(itemList6)){
            JSONArray arrayInfo = JSON.parseArray(itemList6);
            for(int i=0;i<arrayInfo.size();i++){
                JSONObject jsonObject1 = JSON.parseObject(arrayInfo.get(i).toString());

                String warehouseCode;
                if (jsonObject1.get("warehouseCode") == null){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("仓库代码不能为空!");
                }
                warehouseCode=jsonObject1.get("warehouseCode").toString();
                String key = warehouseCode;
                if (map.get(warehouseCode) == null){
                    map.put(warehouseCode,key);
                }else {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return R.error("不能新增相同数据");
                }
            }
            if(arrayInfo!=null && arrayInfo.size()>0){
                logger.info("物流服务维护维护管理子表信息："+arrayInfo);
                for(int i=0;i<arrayInfo.size();i++){
                    TccAdditionalBillingTwo tccAdditionalBillingTwo = JSON.parseObject(JSON.toJSONString(arrayInfo.get(i)), TccAdditionalBillingTwo.class);
                    tccAdditionalBillingTwo.setStatus(1);
                    tccAdditionalBillingTwo.setMethodId(tccLogisticsMethod.getId());
                    tccAdditionalBillingTwoMapper.insert(tccAdditionalBillingTwo);

                }
            }
        }


        return R.ok(AddDto.gotoEdit("/web/storage/tccLogisticsMethod/toEdit?id=" + tccLogisticsMethod.getId()));
        //return R.ok();
    }



    /**
     * 参数验证
     */
    public String checkParams(Map<String, Object> params, Long menuId) throws Exception {
        //获取pc字段数据
        List<YsCol> listField = new YsCol()
                .where("A.MenuId = " + menuId)
                .setOrderby("A.SortNo ASC")
                .queryList();
        //验证必填字段的非空；其他字段的长度限制、类型
        String backMsg = checkUtil.checkTableColLengthAndDataType("TCC_LogisticsMethod", listField, params, ysColItem -> ysColItem.getFormEditRequired() != null && ysColItem.getFormEditRequired() == 1);
        return backMsg;
    }


    //根据主表bid获取子表信息
    @Override
    @Transactional(timeout = 120, propagation = Propagation.REQUIRES_NEW)
    public List<Map<String, Object>> getItemListById(Long id) throws Exception {
        //获取子表信息
        List<Map<String, Object>> itemList = new TccPreAllocatePublishItem()
                .queryMap();
        return itemList;
    }

    @Override
    public R editDetailBatch(Long logisticsMethodId, String detailArr) {

        if (logisticsMethodId == null) {
            return R.error("提交的参数有误，请联系客服");
        }
        TccLogisticsMethod tccLogisticsMethod = new TccLogisticsMethod().setId(logisticsMethodId).queryFirst();

        JSONArray detailJA = JSON.parseArray(detailArr);

        // 验证数据是否已存在
        List<String> listUnicode = new ArrayList<String>();
        for (int i = 0; i < detailJA.size(); i++) {
            JSONObject detailJO = detailJA.getJSONObject(i);
            String startheavy = detailJO.getString("startheavy");
            String heavyFee = detailJO.getString("heavyFee");
            // 添加调货信息
            BigDecimal originPriceMin = BigDecimal.ZERO;
            BigDecimal originPriceMax = BigDecimal.ZERO;
            return R.ok();
        }
        return null;
    }

    //获取列表数据
    @Override
    @Transactional
    public Map<String,Object> getExtraParam(Long id) throws Exception{
        Map<String, Object> entity = new TccLogisticsMethod().setId(id)
                .queryFirstMap();
        entity.put("status", 1);
        entity.put("cck", "CK00001");
        entity.put("vck", "福州仓");
        return entity;
    }


    
    //删除
    @Override
    public int del(long id) throws Exception{
        tccLogisticsMethodMapper.deleteTrue(id);
        return 1;
    }
}
